<?php

namespace App\Admin\Controllers;



use App\Admin\Repositories\VisitorReservesLog;
use App\Models\Reserves as ReservesModel;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class VisitorReservesLogController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new VisitorReservesLog(), function (Grid $grid) {
            $grid->model()->orderBy('id', 'desc');

            $grid->column('id')->sortable();
            $grid->column('visitor_reserves_id');
            $grid->column('visitor_id');
            $grid->column('interviewee_information_id');
            $grid->column('reason');
            $grid->column('device_groups');
            $grid->column('source');
            $grid->column('start_time');
            $grid->column('end_time');
            $grid->column('interviewee_name');
            $grid->column('interviewee_phone');
            $grid->column('interviewee_openId');
            $grid->column('visitor_name');
            $grid->column('visitor_telephone');
            $grid->column('visitor_openId');
            $grid->column('appId');
            $grid->column('authorId');
            $grid->column('captcha');
            $grid->column('passType');
            $grid->column('peers');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new VisitorReservesLog(), function (Show $show) {
            $show->field('id');
            $show->field('visitor_reserves_id');
            $show->field('visitor_id');
            $show->field('interviewee_information_id');
            $show->field('reason');
            $show->field('device_groups')->as(function ($value){
                $string = '';
                foreach ($value as $item) {
                    $string .= ReservesModel::$deviceGroups[$item] ?? '';
                }
                return $string;
            });
            $show->field('source')->as(function ($value){
                return  ReservesModel::$source[$value] ?? '';
            });
            $show->field('start_time');
            $show->field('end_time');
            $show->field('interviewee_name');
            $show->field('interviewee_phone');
            $show->field('interviewee_openId');
            $show->field('visitor_name');
            $show->field('visitor_telephone');
            $show->field('visitor_openId');
            $show->field('appId');
            $show->field('authorId');
            $show->field('captcha');
            $show->field('passType');
            $show->field('peers');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new VisitorReservesLog(), function (Form $form) {
            $form->display('id');
            $form->text('visitor_reserves_id');
            $form->text('visitor_id');
            $form->text('interviewee_information_id');
            $form->select('reason')->options(ReservesModel::$reason)->required();
            $form->multipleSelect('device_groups')->options(ReservesModel::$deviceGroups)->default(12)->required();
            $form->select('source')->options(ReservesModel::$source)->default(3)->required();
            $form->time('start_time');
            $form->time('end_time');
            $form->text('interviewee_name');
            $form->text('interviewee_phone');
            $form->text('interviewee_openId');
            $form->text('visitor_name');
            $form->text('visitor_telephone');
            $form->text('visitor_openId');
            $form->text('appId');
            $form->text('authorId');
            $form->text('captcha');
            $form->text('passType');
            $form->text('peers');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
